module fn.pattern.Functor


type Functor<'D> (arity: int, f: 'D list -> 'D) =
    class
        let _f = f
        let _arity = arity
        member this.Invoke (args: 'D list) =
          if args.Length=_arity then _f args
          else failwith "wrong number of arguments to f"
        member this.Value = this.Invoke []
        override this.ToString() =
          match _arity with
          | 0 -> (this.Value).ToString()
          | _ -> "Functor"
        new (constant: 'D) = Functor<'D>(0, (fun _ -> constant))
    end

